import {iProcessActionRender} from "../../packages/createVisualEditorUser/createVisualEditorAction/createVisualEditorActionRender";

/**
 * 预定义动作渲染
 * @author  韦胜健
 * @date    2022/2/6 23:37
 */
export const predefineActionRender: iProcessActionRender = ({ actionRender: { registryActionRender } }) => {

  const openFail = (e: any) => {
    e.stopPropagation();
    e.preventDefault();
    alert('当前工程无法跳转页面，请在nuxt或者next工程中使用跳转功能');
  };

  registryActionRender(
    '@@fixed',
    (data, content, attrs) => (
      <a href={data.action?.data} {...attrs}>
        {content}
      </a>
    )
  );

  registryActionRender(
    'pdp',
    (data, content, attrs) => (
      <a href={`pdp/${data.action?.data.id}`} {...attrs} onClick={openFail}>
        {content}
      </a>
    ),);

  registryActionRender(
    'category',
    (data, content, attrs) => (
      <a href={`plp?category=${data.action?.data.id}`} {...attrs} onClick={openFail}>
        {content}
      </a>
    ),
  );

  registryActionRender(
    'bind-product',
    (data, content, attrs) => (
      <a href={`pdp?category=${data.data.product.id}`} {...attrs} onClick={openFail}>
        {content}
      </a>
    ),
  );

  /*registryActionRender(
      'activity',
      (data, content, attrs) => (
          <a href={`activity?category=${data.data.code}`} {...attrs} onClick={(e) => {
              openFail(e)
              !!attrs.onClick && attrs.onClick(e)
          }}>
              {content}
          </a>
      ),
  )*/
};
